package com.softserveinc.autorent.rest;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import com.softserveinc.autorent.controller.CarController;
import com.softserveinc.autorent.model.Car;
import com.softserveinc.autorent.model.CarModel;

@ManagedBean
@RequestScoped
public class CarMB {

	@EJB
	private CarController carController;

	private Car car;
	private DataModel carList;

	public DataModel getCarList() 
	{


		 List<Car> lista = carController.getAll();
		 carList = new ListDataModel(lista);
		 return carList;
	}

	public Car getCar() {
		return car;
	}

	public void setCar(Car car) {
		this.car = car;
	}

	public String prepareBookCar() {
		car = (Car)(carList.getRowData());
		return "book";
	}

	public String prepareAddCar() {
		car = (Car)(carList.getRowData());		
		return "Create person";
	}

	public String prepareUpdateCar() {
		car = (Car) (carList.getRowData());
		return "Create person";
	}

	public String deleteCar() {

		Car car = (Car) (carList.getRowData());
		carController.delete(car);
		return "index";

	}

	public String addCar() {
		carController.create(car);
		return "index";

	}

	public String updateCar() {
		carController.update(car);
		return "index";

	}
}
